package com.jason.kotlin.gank

import android.content.Context
import android.location.Address
import android.location.Geocoder
import android.location.Location
import android.util.Log
import java.util.*

object LocationHelper {

    fun getAddress(context: Context,location : Location?) :List<Address>  {
        var result = mutableListOf<Address>()
        try {
            if (location != null) {
                val gc = Geocoder(context, Locale.getDefault());
                result = gc.getFromLocation(location.latitude,
                    location.longitude, 1)
            }
            if(result.size > 0) {
                Log.i("chenby",result[0].toString())
            }

        } catch (e: Exception) {
            e.printStackTrace()
        }
        return result;
    }
}